import Vue from 'vue'
import Vuex from 'vuex'
import searchHistory from './modules/searchHistory'
import router from './modules/router'
import shopCar from './modules/shopCar'
import user from './modules/user'
import address from './modules/address'
Vue.use(Vuex)
const store = new Vuex.Store({
  modules: {
    searchHistory,
    router,
    shopCar,
    user,
    address
  },
  state: {
    fetchCount: 0,
    loading: false
    // 请求数据时加载状态loading
  },
  mutations: {
    // 请求数据时loading
    showLoading(state){
      state.loading = true    
    },
    hideLoading (state) {
      state.loading = false
    }
  },
  getters: {
    fetchCount(state) {
      return state.fetchCount
    }
  },
  actions: {
    set_fetch_count({
      commit,
      state
    }, b) {
      commit('setFetchZero', b)
    },
    set_fetch_zero({
      commit,
      state
    }) {
      state.fetchCount = 0
    }
  }
})

export default store